# 自定义过滤器


def index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''

from functools import wraps
from flask import session
from info.models import User
from flask import g

def user_login_data(view_func):
    @wraps(view_func)
    def wrapper(*args,**kwargs):
        # 1.获取sesion用户编号
        user_id = session.get('user_id')

        # 2.根据用户编号获取对象
        user = None
        if user_id:
            user = User.query.get(user_id)

        # 3.把user数据添加到g对象
        g.user = user

        return view_func(*args,**kwargs)
    return wrapper
